// pages/reserve/record/index.js
var app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        status:0,
        list:[],
        pagination:{page:1},
        topNavH:'',
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
      const that = this;
      wx.getSystemInfo({
        success: res => {
          var statusBarHeight = res.statusBarHeight;
          // console.log('statusBarHeight:' + statusBarHeight)
          var topNavH = (statusBarHeight + 45);
          that.setData({
            topNavH: topNavH + 'px',
          })
        }
      })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {
        this.getRecords();
    },
    getRecords(){
        const that = this;
        wx.request({
          url: app.globalData.apiUrl + 'api/activity/index',
          method: 'POST',
          data: {
            'openid':wx.getStorageSync('openid'),
            'status':that.data.status,
            'page':that.data.pagination.page
          },
          header: {
            'Content-Type': 'application/json'
          },
          success: function (res) {
            console.log(res.data)
            let response = res.data.data;
            that.setData({
                list:response
            })
          },
          fail: function () {
            
          },
          complete: function () {
          }
        })
      },
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function (res) {
    return {
      title: '青岛市特种设备安全智慧体验中心',
      path: '/pages/bm/index/index',
      success: function (res) {
        wx.showToast({
          title: '已转发',
          icon: 'success',
          duration: 2000
        })
      }
    }

  },
    setActive(e){
        let type = e.currentTarget.dataset.status;
        if(this.data.status != type) {
            this.data.list = [];
        }
        this.setData({
            status:e.currentTarget.dataset.status
        })
        this.getRecords();
    },
    navigateDetail(e){
        console.log(e)
        wx.navigateTo({
          url: '/pages/bm/detail/index?id='+e.currentTarget.dataset.id,
        })
    }
})